//
//  WeMyAuctionTopSelectView.m
//  WeGalaxy
//
//  Created by Zheng on 2017/7/7.
//  Copyright © 2017年 Zheng. All rights reserved.
//

#import "WeMyAuctionTopSelectView.h"

@implementation WeMyAuctionTopSelectView

#pragma mark - 点击事件
- (void)topClickAction:(UIButton *)sender {
    
    CGFloat x = 0;
    WeMyAuctionTopSelectType type = WeMyAuctionTopSelectTypeCompete;
    
    if (sender == _competeBtn) {
        x = 0;
        type = WeMyAuctionTopSelectTypeCompete;
    } else if (sender == _finishBtn) {
        x = kSCREEN_WIDTH*0.3+kSCREEN_WIDTH*0.1/2.f;
        type = WeMyAuctionTopSelectTypeFinish;
    } else {
        x = kSCREEN_WIDTH*0.7;
        type = WeMyAuctionTopSelectTypeOrder;
    }
    
    _selectTypeBlock(type);
    
    [UIView animateWithDuration:kANIMATION_DURATION animations:^{
        _redView.frame = (CGRect){x,45,kSCREEN_WIDTH*0.3,7};
    }];
}

#pragma mark - 初始化
- (instancetype)init {
    self = [super init];
    if (self) {
        [self viewsInView];
    }
    return self;
}

#pragma mark - 子视图
- (void)viewsInView {
    
    [self addSubview:self.competeBtn];
    [self addSubview:self.finishBtn];
    [self addSubview:self.orderBtn];
    [self addSubview:self.redView];
    [self addSubview:self.lineView];
    
    [_competeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.left.equalTo(self);
        make.width.equalTo(self).multipliedBy(0.3);
    }];
    
    [_finishBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.centerX.equalTo(self);
        make.width.equalTo(_competeBtn);
    }];
    
    [_orderBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.right.bottom.equalTo(self);
        make.width.equalTo(_competeBtn);
    }];
    
    [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.equalTo(self);
        make.height.mas_equalTo(0.5);
    }];
    
}

- (UIButton *)competeBtn {
    if (!_competeBtn) {
        _competeBtn = [self getAuctionTopButtonWithTitle:@"参拍的"];
    }
    return _competeBtn;
}

- (UIButton *)finishBtn {
    if (!_finishBtn) {
        _finishBtn = [self getAuctionTopButtonWithTitle:@"已结束"];
    }
    return _finishBtn;
}

- (UIButton *)orderBtn {
    if (!_orderBtn) {
        _orderBtn = [self getAuctionTopButtonWithTitle:@"订单"];
    }
    return _orderBtn;
}


- (UIButton *)getAuctionTopButtonWithTitle:(NSString *)title {
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setTitle:title forState:UIControlStateNormal];
    button.titleLabel.font = kCX_FONT(13);
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(topClickAction:) forControlEvents:UIControlEventTouchUpInside];
    return button;
}

- (UIView *)lineView {
    if (!_lineView) {
        _lineView = [UIView new];
        _lineView.backgroundColor = kRGB_COLOR(153, 152, 151, 1);
    }
    return _lineView;
}

- (UIView *)redView {
    if (!_redView) {
        _redView = [UIView new];
        _redView.frame = (CGRect){0,45,kSCREEN_WIDTH*0.3,7};
        _redView.backgroundColor = kRGB_COLOR(245, 67, 55, 1);
    }
    return _redView;
}


@end
